package com.clz.appdesign.appdependence.baseKotlin.mvp

import android.os.Bundle

import com.clz.appdesign.appdependence.baseKotlin.BaseFragment


/**
 * @author chenliangzhi
 * @date 2018/3/19
 * @describe
 */

abstract class MvpFragment<V, P : BasePresenter<V>> : BaseFragment() {
    protected lateinit var mPresenter: P

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun beforeInit() {
        super.beforeInit()
        mPresenter = initPresenter()
        mPresenter.attach(this as V)
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
    }

    override fun onDestroyView() {
        mPresenter.detach()
        super.onDestroyView()
    }

    /**
     * 初始化presenter
     *
     * @return
     */
    abstract fun initPresenter(): P
}
